package br.com.massai.model.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import br.com.massai.view.enums.StatusEnum;

@Entity
@Table(name = "GRUPO_PRODUCAO", schema = "PORTAL")
@SequenceGenerator(name = "seqGrupoProducao", sequenceName = "seq_grupo_producao", allocationSize = 1)
@NamedQueries({
	@NamedQuery (name = "GrupoProducao.findAll", query = "SELECT gp FROM GrupoProducao gp"),
	@NamedQuery (name = "GrupoProducao.duplicata", query = "SELECT COUNT(gp) FROM GrupoProducao gp WHERE LOWER(gp.descricao) = LOWER(:descricao) AND gp.id <> :id")
})
public class GrupoProducao implements Serializable {

	private static final long serialVersionUID = -7066543319875643675L;

	@Id
	@Column(name = "ID_GRUPO_PRODUCAO")
	@GeneratedValue(generator = "seqGrupoProducao", strategy = GenerationType.SEQUENCE)
	private Long id;

	@Column(name = "DESCRICAO", length = 255, unique = true, columnDefinition = "VARCHAR(255)")
	private String descricao;

	@Enumerated(EnumType.STRING)
	@Column(name = "STATUS")
	private StatusEnum status;

	@OneToMany(mappedBy = "grupoProducao", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
	private List<ItemPlanilha> itensPlanilha;
	
	@OneToMany(mappedBy = "grupoProducao", fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
	private List<Obra> obras;
	
	public GrupoProducao() {
		itensPlanilha = new ArrayList<ItemPlanilha>();
		obras = new ArrayList<Obra>();
	}
	
	public GrupoProducao(StatusEnum status) {
		this.status = status;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getDescricao() {
		return descricao;
	}

	public void setDescricao(String descricao) {
		this.descricao = descricao;
	}

	public StatusEnum getStatus() {
		return status;
	}

	public void setStatus(StatusEnum status) {
		this.status = status;
	}

	public List<ItemPlanilha> getItensPlanilha() {
		return itensPlanilha;
	}

	public void setItensPlanilha(List<ItemPlanilha> itensPlanilha) {
		this.itensPlanilha = itensPlanilha;
	}

	public List<Obra> getObras() {
		return obras;
	}

	public void setObras(List<Obra> obras) {
		this.obras = obras;
	}
}
